<!DOCTYPE html >
<html>
<head>
    <base>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>原材料采购审核</title>
    <link rel="stylesheet" href="/res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/res/js/util.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
    <!--模糊搜索区域-->
    <link rel="stylesheet" href="../../css/oksub.css">
    <style>
        body {
            margin: 10px;
        }

        .demo-carousel {
            height: 300px;
            line-height: 300px;
            text-align: center;
        }
        .layui-form-select .layui-edge{
            margin-top: 13px;
        }
    </style>
</head>
<body>
<!--当前状态 根据状态定职位-->
<input type="hidden" name="status" id="status">
<div class="ok-body">
    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form layui-col-md12 ok-search">
            <input class="layui-input" placeholder="请输入供应商名称" autocomplete="off" name="supName">
            <input class="layui-input" placeholder="请输入审核人" autocomplete="off" name="purchasePerson">
            <input class="layui-input" placeholder="开始日期" autocomplete="off" id="startTime" name="startTime">
            <input class="layui-input" placeholder="截止日期" autocomplete="off" id="endTime" name="overTime">
            <div class="layui-inline" style="margin-left: 10px;">
                <div class="layui-input-inline">
                    <select name="reviewState"  lay-search="">
                        <option value="">选择按钮类型</option>
                        <option value="20">待审核</option>
                        <option value="60">总公司总经理通过</option>
                        <option value="61">总公司总经理不通过</option>
                    </select>
                </div>
            </div>
            <button class="layui-btn" lay-submit="" lay-filter="search">
                <i class="layui-icon layui-icon-search"></i>
            </button>

        </form>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="goods" lay-filter="demo"></table>
</div>


<script type="text/html" id="xx">
    <a class="layui-btn layui-btn-xs" lay-event="chakan" id="dindanxx">查看订单详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="chakansh" id="shenhecx">查看审核详情</a>
</script>


<script src="/res/layui/layui.js"></script>
<script type="text/html" id="barDemo">
    {{# if(returnUser()){ }}
        {{# if(authorization("audit:managerAudit") ){ }}
            {{# if(d.isva<60){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('60')" lay-event="audit" >审核</a>
            {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else if(authorization("audit:sellAudit")){ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# } }}
    {{# }else{ }}
        <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
    {{# } }}
</script>
<script type="text/html" id="zt">
    {{zt(d)}}
</script>
<script>
    function zt(d) {
        if(d.isva == '20'){
            return '<p class="layui-btn layui-btn-danger layui-btn-xs">待审核</p>';
        }else if(d.isva == '60'){
            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司总经理通过</p>';
        }else if(d.isva == '61'){
            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司总经理不通过</p>';
        }else if(d.isva == '68'){
            return '<p class="layui-btn layui-btn-warm layui-btn-xs">提交财务申请,等待总公司财务审核</p>';
        }else if(d.isva == '70'){
            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司财务审核通过</p>';
        }else if(d.isva == '71'){
            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司财务审核不通过</p>';
        }else if(d.isva == '80'){
            return '<p class="layui-btn layui-btn-warm layui-btn-xs">分公司财务通过</p>';
        }else if(d.isva == '81'){
            return '<p class="layui-btn layui-btn-danger layui-btn-xs">分公司财务不通过</p>';
        }else if(d.isva == '90'){
            return '<p class="layui-btn layui-btn-normal layui-btn-xs">未入库</p>';
        }else if(d.isva == '91'){
            return '<p class="layui-btn layui-btn-normal layui-btn-xs">已入库</p>';
        }
    }



    var openIndex = null;
    var table = null;
    layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function () {
        table = layui.table;
        var laydate = layui.laydate //日期
            , laypage = layui.laypage //分页
            , layer = layui.layer //弹层
            //, table = layui.table //表格
            , upload = layui.upload //上传
            , element = layui.element; //元素操作
        let form = layui.form;



        //监听Tab切换
        element.on('tab(demo)', function (data) {
            layer.msg('切换了：' + this.innerHTML);
            console.log(data);
        });
        //执行一个 table 实例
        let roleTable = table.render({
            elem: '#goods'
            // , height: 474
            , url: '/auditRecord/RawMaterialShowList' //数据接口
            , page: true //开启分页
            , method: 'post'
            ,height: 'full-200', cellMinWidth: 80 //最大化适应
            ,height:600
            ,totalRow: true  //开启合计
            , cols: [[ //表头
                //{type: 'checkbox', fixed: 'left'}
                 {field: 'purchaseId', title: '序号', width: 80, fixed: 'left', align: 'center',type: 'numbers',unresize: true, sort: 'true', totalRowText: '合计'}
                ,{field: 'supName', title: '供应商名称', width: 120, align: 'center'}
                , {field: 'purchasePerson', title: '采购人', width: 120, align: 'center'}
                , {field: 'purchaseTime', title: '采购时间', width: 160, align: 'center'}
                , {field: 'purchaseSumprice', title: '采购总金额', width: 120, align: 'center', totalRow: true}
                , {field: 'count', title: '采购总数量', width: 80, align: 'center', totalRow: true}
                , {field: 'isva', title: '采购状态', minwidth: 220, unresize : true,  align: 'center', templet: '#zt'}
                , {field: 'remark', title: '采购备注', width: 120, align: 'center'}
                , {field: 'opTime', title: '操作时间', width: 160, align: 'center'}
                , {fixed: 'right', title: '查询信息', width: 210, align: 'center', toolbar: '#xx'}
                , {fixed: 'right', title: '操作', width: 140, align: 'center', toolbar: '#barDemo'}
            ]]
            , id: 'testReload'
            ,where: {   //原材料过滤状态为0,10
                isva : "0,10"
            }
        });

        //查询条件
        form.on("submit(search)", function (data) {
            console.info(data)
            roleTable.reload({
                where: data.field,
                page: {curr: 1}
            });
            console.log("0000")
            return false;
        });

        //日期时间选择器
        laydate.render({
            elem: "#startTime",
            theme: 'molv',
            type: "datetime"});
        laydate.render({
            elem: "#endTime",
            type: "datetime",
            theme: 'molv'
        });

        //监听工具条
        table.on('tool(demo)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            console.info(data);
            if (layEvent === 'chakan') {
                //查看订单
                var url = "/ok-admin/pages/purchaseorder/purchasedetails.html?purchaseId=" + data.purchaseId;
                layer.open({
                    type: 2,
                    area: ['76%', '75%'],//弹出框大小
                    shift: 1,//弹出框动画效果
                    content: [url, 'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            } else if (layEvent === 'chakansh') {
                //根据原材料订单编号查看审核表记录
                openIndex = layui.layer.open({
                    type: 2,
                    title: '审核详情',
                    area : ['80%' , '85%'],//弹出框大小
                    anim:1,
                    shadeClose:true,//点击也能遮罩层关闭
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    content: '/ok-admin/pages/audit/auditList.html?marketId='+ data.purchaseId //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }else if(obj.event === "audit"){
                var id = data.purchaseId;
                //获取所点击审核的人的权限
                let status = $("#status").val();

                openIndex = layui.layer.open({
                    type: 2,
                    area: ['55%', '60%'], //宽高
                    title: '审核信息',
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shadeClose:true,//点击也能遮罩层关闭
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    // content:  $("#popUpdateTest"),
                    content:`/ok-admin/pages/audit/auditForm.html?id=${id}&status=${status}&audit=rawMaterial`
                });
            }
        });
        //审核请求
        window.openAudit = function (status) {
            $("#status").val(status);
        }
    });

    /**
     * 关闭层
     * @param msg 返回信息
     */
    function closeOpen(msg) {
        //语音播放
        playMessage(msg);
        layer.close(openIndex);
        layer.msg(msg, {time: 1500,icon:1}, function () {
            table.reload("testReload");//刷新表格
        })
    }
    /**
     * 错误提示 关闭弹出层
     */
    function errorCloseOpen(msg){
        //语音播放
        playMessage(msg);
        layer.close(openIndex);
        layer.msg(msg,{time:2000,icon:2},function(){
            table.reload("testReload");
            //window.location.reload(true);
        });
    }

    function closeOpens() {
        table.reload("testReload");//刷新表格
    }


</script>
</body>
</html>